package com.zhudeshuai.zhudemolist.rn.module;

import android.widget.Toast;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;

/**
 * 对RN提供Toast原生方法
 *
 * @author zhudeshuai
 * @since 2018/2/2
 */

public class ToastModule extends BaseReactModule {

	private static final String DURATION_SHORT_KEY = "SHORT";
	private static final String DURATION_LONG_KEY = "LONG";

	public ToastModule(ReactApplicationContext reactContext) {
		super(reactContext);
	}

	/**
	 * 返回给js使用的一些常量
	 *
	 * @return
	 */
	@Nullable
	@Override
	public Map<String, Object> getConstants() {
		final Map<String, Object> constants = new HashMap<>();
		constants.put(DURATION_LONG_KEY, Toast.LENGTH_LONG);
		constants.put(DURATION_SHORT_KEY, Toast.LENGTH_SHORT);
		return constants;
	}

	@ReactMethod
	public void show(String message, int duration) {
		Toast.makeText(getReactApplicationContext(), message, duration).show();
	}
}
